package com.ruoyi.fly.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.fly.domain.ChlCoupons;
import com.ruoyi.fly.domain.vo.ChlCouponsSearchVo;
import com.ruoyi.fly.domain.vo.ChlCouponsVo;
import com.ruoyi.fly.domain.vo.DeleteVo;
import com.ruoyi.fly.service.ChlCouponsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: wdf
 * @Date: 2024/6/7
 */
@RestController
@RequestMapping("/coupons")
@Api(tags = "消费金管理")
public class ChlCouponsController extends BaseController {

    @Autowired
    private ChlCouponsService chlCouponsService;

    /**
     * 查看消费金列表
     */
    @ApiOperation(value = "查看消费金列表")
    @PostMapping("/selectCouponsList")
    public R<ChlCoupons> selectCouponsList(@RequestBody ChlCouponsSearchVo chlCouponsSearchVo) {
        return chlCouponsService.selectChlCouponsList(chlCouponsSearchVo);
    }

    /**
     * 添加消费金
     */
    @ApiOperation(value = "添加消费金")
    @PostMapping("/addCoupons")
    public R<ChlCoupons> addCoupons(@RequestBody ChlCouponsVo chlCoupons) {
        return chlCouponsService.insertChlCoupons(chlCoupons);
    }

    /**
     * 修改消费金
     */
    @ApiOperation(value = "修改消费金")
    @PostMapping("/editCoupons")
    public R<ChlCoupons> editCoupons(@RequestBody ChlCouponsVo chlCoupons) {
        return chlCouponsService.updateChlCoupons(chlCoupons);
    }

    /**
     * 删除消费金
     */
    @ApiOperation(value = "删除消费金")
    @PostMapping("/deleteCoupons")
    public R<ChlCoupons> deleteCoupons(@RequestBody DeleteVo deleteVo) {
        if (StringUtils.isEmpty(deleteVo.getIds())){
            return R.fail("参数不能为空");
        }
        return chlCouponsService.deleteChlCouponsByIds(deleteVo.getIds());
    }
}
